'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceBackdepositapplyCtrl
 * @description
 * # FinanceBackdepositapplyCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceBackdepositapplyCtrl', function ($scope, $rootScope, openApi, Util, $location, $routeParams, localStorageService, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
            // 底部款项类型选框添加
        var selectData, params, relModuleObj = {};
        $scope.payWayList = [{
            key: "银行保函",
            value: 1
        }, {
            key: "柜台转账",
            value: 2
        }, {
            key: "网银转账",
            value: 3
        }, {
            key: "银行汇票",
            value: 4
        }];
        $scope.disabled = function () {
            var checked = true;
            if (!$scope.param) {
                return
            }
            if ($scope.param.payType == 3) {
                checked = false;
            }
            return checked
        };
        $scope.submit = function (operationId) {

            $scope.param.receiveDetail = angular.toJson($scope.param.receiveList)
                // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.depositApply;
            options.param = angular.copy($scope.param, {});
            options.param["formBidApply.formId"] = options.param.formBidApply && options.param.formBidApply.formId || "";
            delete options.param.fundSoruceList
            delete options.param.receiveList
            delete options.param.formBidApply
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if (!$scope.param.payWay) {
                Util.Toast("请选择付款方式");
                return;
            }
            if (!$scope.param.receiveMoney) {
                if ($scope.param.receiveMoney !== 0) {
                    Util.Toast("请填写收款金额");
                    return;
                }
            }
            if (!$scope.param.endDate) {
                Util.Toast("请选择到账截至日期");
                return;
            }
            if (!$scope.param.remark) {
                Util.Toast("请填写备注");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                $scope.param.payType = 3;
                // 根据后台返回的字符串创建列表，后台没有返回的话就初始化一个列表
                $scope.param.receiveList = $scope.param.receiveDetail && JSON.parse($scope.param.receiveDetail) || [];
            });
        };
        // 初始化
        init();
    });